<template>
	<z-paging ref="paging" class="balance-list" v-model="datalist" @query="queryList" default-page-size="15">
		<view class="balance-list-box">
			<view class="balance-list-item" v-for="(item, index) in datalist" :key="index">
				<view class="item-left">
					<image src="../../static/images/user/free.png" class="image"></image>
				</view>
				<view class="item-center">
					<view class="name">{{item.name}}</view>
					<view class="time">有效期:{{item.expiration_time_text}}</view>
				</view>
				<view class="item-right">
					<view class="use" v-if="item.status=='created'" @click="toUse">使用</view>
					<image src="../../static/images/user/use.png" class="expired" v-if="item.status=='paid'"></image>
					<image src="../../static/images/user/expired.png" class="expired" v-if="item.status=='expired'">
					</image>
				</view>
			</view>
		</view>
	</z-paging>
</template>

<script>
	import api from '@/api/index.js';
	export default {
		data() {
			return {
				datalist: []
			};
		},
		methods: {
			//去使用
			toUse(){
				uni.switchTab({
					url:"/pages/home/index"
				})
			},
			/**
			 * 获取我的免单券
			 */
			queryList(pageNo, pageSize) {
				api.getFreeCouponList({
					page: pageNo,
					limit: pageSize,
				}).then(res => {
					this.$refs.paging.complete(res.data);
				}).catch(res => {
					this.$refs.paging.complete(false);
				})
			},
		}
	};
</script>

<style lang="scss">
	.balance-list {
		background: #f8f8f8;
		padding: 28rpx;

		.top-search {
			background: #ffffff;
			box-shadow: 0px 12rpx 116rpx 0px rgba(196, 203, 214, 0.1);
			border-radius: 24rpx;
			display: flex;
			align-items: center;
			padding: 26rpx 40rpx;
			margin: 20rpx 20rpx 0;

			.input {
				flex: 1;
				font-family: PingFangSC, PingFang SC;
				font-weight: 400;
				font-size: 32rpx;
				color: #7d8592;
				line-height: 44rpx;
				text-align: left;
				font-style: normal;
			}

			.image {
				width: 48rpx;
				height: 48rpx;
			}
		}

		.balance-list-box {
			margin: 20rpx;

			.balance-list-item {
				background: #ffffff;
				box-shadow: 0px 4rpx 8rpx 0px rgba(41, 121, 255, 0.05);
				border-radius: 16rpx;
				border: 2rpx solid;
				border-image: linear-gradient(180deg, rgba(255, 255, 255, 0), rgba(255, 255, 255, 1)) 1 1;
				padding: 26rpx 30rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;
				margin-top: 20rpx;

				.item-left {
					margin-right: 20rpx;

					.image {
						width: 124rpx;
						height: 124rpx;
					}
				}

				.item-center {
					flex: 1;

					.name {
						font-size: 32rpx;
						color: #333333;
						font-weight: bold;
						margin-bottom: 20rpx;
					}

					.time {
						font-size: 24rpx;
						color: #999999;
					}
				}

				.item-right {
					.use {
						width: 118rpx;
						height: 52rpx;
						background: #4B9EFC;
						border-radius: 100rpx;
						font-size: 24rpx;
						color: #FFFFFF;
						text-align: center;
						line-height: 52rpx;
					}

					.expired {
						width: 152rpx;
						height: 152rpx;
					}
				}
			}
		}
	}
</style>